using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Formular;

namespace Pixysoft.Weblications.Sango.Battle
{
    class BattleMagicAttackSingle : BattleAttack, IBattleAttack
    {
        public BattleMagicAttackSingle()
            : base(AttackTypecodeCollection.MAGIC_ATTACK)
        {
        }

        public void apply(BattleHistory history, Battler attacker, BattleTeam attacks, BattleTeam defenses)
        {
            Battler defenser = defenses.getOneApplier(attacker);

            if (defenser == null)
                return;

            BattleActionHistory action = history.createAction(attacker, BattleActionTypecodeCollection.MAGIC_ATTACK);
            action.setAttack(this);

            if (!BattleFormular.attackHit(attacker, defenser))
            {
                action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_MISS).Defenser = (defenser.createHistory());
                return;
            }

            long hpValue = BattleFormular.magicAttackDamage(attacker, defenser);

            defenser.reduceHpPointValue(hpValue);

            BattleActionItemHistory attackActionItem = action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_SUCCEED);

            attackActionItem.Attacker = attacker.createHistory();

            attackActionItem.Defenser = defenser.createHistory();
        }

    }
}